/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 * Name       : 装置查询统计
 */

var fieldLabel=new Array('地区','合计','A类','B类','C类','D类');
var fieldName=new Array('company','number','aNumber','bNumber','cNumber','dNumber');
var _pageSize=100;
var record_start = 0;


var pointType2Store = new Ext.data.JsonStore({
    url:  '../../../servlet/common/SimpleInfoLoad',
    baseParams: {id: 'id', name: 'name', tableName: 't_pointType2'},
    autoLoad: true,
    root: 'data',
    fields: ['id', 'name']
});

var pointType2Combo = {
    xtype: 'combo',
    width: 125,
    store: pointType2Store,
    id: 'PointType2Combo',
    displayField: 'name',
    valueField: 'id',
    hiddenName: 'pointType2Id',
    mode: 'remote',
    forceSelection: true,
    triggerAction: 'all',
    fieldLabel: '城农网类别',
    emptyText: '城农网类别...',
    selectOnFocus: true,
    listeners: {
        select: function(combo, record, index) {
            store.baseParams.pointType2Id = combo.getValue();
        }
    }
};

var state={
        xtype:'combo',
        width:120,
        fieldLabel: '在线情况',
        mode: 'local',
        emptyText: '选择在线情况...',
        allowBlank: false,
        //msgTarget: 'side',
        id: 'state',
        triggerAction: 'all',
        forceSelection:true,
        store: new Ext.data.ArrayStore({
            fields: [
            'id',
            'stateType'
            ],
            data: [['1', '全部'], ['2', '在线'],['3', '离线']]
        }),
        valueField: 'id',
        displayField: 'stateType',
        anchor: '50%'
    }

var store=new Ext.data.JsonStore({               
    //data: [
    //       ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '17']
    //]
    url: "../../servlet/report/gridvoltagepoint",
    root: 'data',
    idProperty: 'id',
    totalProperty: 'count',
    fields: fieldName,
    autoLoad: true
});

var now = new Date();
var beginDate = now.format('Y-m-d');
var endDate=now.add(Date.MONTH,-1).format('Y-m-d');
var dateFrom = {
    xtype: 'datefield',
    id: 'DateFrom',
    format: 'Y年m月d日',
    width: 150,
    value:now.add(Date.MONTH,-1),
    listeners: {
        select: function(c, date) {
            beginDate = date.format('Y-m-d');
            store.baseParams.beginDate = beginDate;
        }
    }  
}

var dateTo={
    xtype: 'datefield',
    id: 'DateTo',
    format: 'Y年m月d日',
    width: 150,
    value:now,
    listeners: {
        select: function(c, date) {
            beginDate = date.format('Y-m-d');
            store.baseParams.beginDate = beginDate;
        }
    }
}

var colModel = new Ext.grid.ColumnModel({
    columns: [
    new Ext.grid.RowNumberer({
        header : '序号',
        align: 'center', 
        width : 40,
        renderer: function (value, metadata, record, rowIndex) {
            return record_start + 1 + rowIndex;
        }
        
    }),
        {header: fieldLabel[0],width: 100, dataIndex: fieldName[0], align: 'center'},
        {header: fieldLabel[1],width: 100, dataIndex: fieldName[1], align: 'center'},
        {header: fieldLabel[2],width: 100, dataIndex: fieldName[2], align: 'center'},
        {header: fieldLabel[3],width: 100, dataIndex: fieldName[3], align: 'center'},
        {header: fieldLabel[4],width: 100, dataIndex: fieldName[4], align: 'center'},
        {header: fieldLabel[5],width: 100, dataIndex: fieldName[5], align: 'center'},
    ],
    defaultSortable: true
});

var grid=new Ext.grid.GridPanel({
    title: '装置查询统计',
        store: store,
        colModel:colModel,
        enableColumnMove: false,
        viewConfig: {
            forceFit: true
        },
        
        loadMask: true,
        tbar: new Ext.Toolbar([
        pointType2Combo,
        '-',
        state,
        '-',
        {
            text: "生效日期：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        }
        ,
        dateFrom,
        '-',
        {
            text: "至：", 
            xtype: 'label', 
            style: {
                marginLeft: '20px'
            }
        },
        dateTo,
        '-',
        {
            xtype: 'button',
            text: '搜索',
            iconCls: 'icon-search',
            width: 60,
            style: {
                marginLeft: '20px'
            },
            handler: function() {
                store.load({
                    params: {
                        start: 0, 
                        limit: _pageSize
                    }
                });
            }
        },
        ]),
        bbar: new Ext.PagingToolbar({
            pageSize: _pageSize,
            store: store,
            displayInfo: true,
            displayMsg: '显示记录：{0} - {1}   总记录：{2}',
            emptyMsg: '目前没有信息'
        })
    });
    store.load({
        params: {
            start: 0, 
            limit: _pageSize
        }
    });



function buildWindow(){
    var applicationUI = new Ext.Viewport({
        layout:'fit',
        items: [
        grid
        ]
    });
}
Ext.onReady(buildWindow); 